package com.orange.modules.dao;

import java.sql.SQLException;
import java.util.List;

import javax.annotation.Resource;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.orange.dbhelp.DbHelper;
import com.orange.modules.entity.AuthSchoolExpertFile;

@Repository
public class AuthSchoolExpertFileRepository {

	@Resource(name = "dbHelper")
	private DbHelper dbHelper;
	
	@Autowired
	private AuthSchoolExpertFileDao authSchoolExpertFileDao;
	/**
	 * 保存专家上传的文件
	 * @param as
	 * @throws SQLException
	 */
	public void insertAuthSchoolExpertFile(AuthSchoolExpertFile as) throws SQLException{
		authSchoolExpertFileDao.save(as);
	}
	
	/**
	 * 删除专家上传的文件
	 * @param pid
	 * @throws SQLException
	 */
	public void deleteAuthSchoolExpertFile(String pid) throws SQLException{
		authSchoolExpertFileDao.delete(pid);
	}
	
	/**
	 * 查看该学校 该专家下是否上传过文档
	 * @param sid
	 * @param expertId
	 * @return
	 * @throws SQLException
	 */
	public List<AuthSchoolExpertFile> queryFileByschoolIdExpertId(String sid,String expertId) throws SQLException{
		String sql = "SELECT t.p_id as pid,t.s_id as sid,t.expert_id as expertId,t.s_filepath as filepath,t.s_filename as filename,t.s_createtime as createtime FROM t_auth_school_expert_file t WHERE 1=1 ";
		if(sid!=null && StringUtils.isNotBlank(sid))
			sql+=" AND t.s_id ='"+sid+"'";
		if(expertId!=null && StringUtils.isNotBlank(expertId))
			sql+="	AND t.expert_id='"+expertId+"'";
		List<AuthSchoolExpertFile> list = dbHelper.getBeanList(sql, AuthSchoolExpertFile.class, null);
		return list;
		
	}
}
